#!/bin/bash

set -e

cur_path=$(pwd)

echo "start to prepare ipmi check env"
chmod +x /root/repo/ci-repos/.common_scripts/common.sh
source /root/repo/ci-repos/.common_scripts/common.sh
set_gitee_hosts
prepare_git $1 $2

cd ${cur_path}

function handle_error() {
    local exit_code=$?
    echo "Error occurred in script at line: ${1} with exit code: ${exit_code}"
    exit $exit_code
}

trap 'handle_error ${LINENO}' ERR


function check_ipmi_modify()
{
    echo "start to check ipmi.json..............."
    check_ipmi=0
    is_modefy=$(git diff HEAD~1 -- mds/ipmi.json)
    if [ -n "${is_modefy}" ]; then
        check_ipmi=1
        echo "[ERROR]本PR修改了ipmi.json架构文件，需要进行变更流程遵循确认。本告警仅可以由南北向专家 \
        @huanghan， @xiaoxinglxs，@pengqiang-gs审核屏蔽。请联系committer/maintainer按照南北向专家要求，\
        进行变更流程遵循确认，达成要求后，告警提交至南北向专家处屏蔽。"
    fi
    export check_ipmi

}

check_ipmi_modify

if [ ! $check_ipmi -eq 0 ]; then
    exit 1
fi